//user 模块全局数据仓库
import { LoginUserVO, UserControllerService } from "../../generated";
import AccessEnum from "@/access/accessEnum";

export default {
  namespaced: true,
  state: (): any => ({
    loginUser: {
      userName: "未登录"
    }
  } as LoginUserVO),
  getter: {},
  actions: {
    async getLoginUser({ commit, state }: any, payload: any) {
      //从远程获取登录信息
      const res = await UserControllerService.getLoginUserUsingGet();
      if (res.code === 0) {
        console.log(res.data);
        commit("updateUser", res.data);
      } else {
        commit("updateUser", {
          ...state.loginUser,
          userRole: AccessEnum.NOT_LOGIN
        });
      }
    }
  },
  mutations: {
    updateUser(state: any, payload: any) {
      state.loginUser = payload;
    }
  }
};
